/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Database;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

/**
 *
 * @author PHAMDANH
 */
public class PrimaryKey implements Serializable{
    private String name;
    private List<String> pkColumns;//các cột khóa chính
    public PrimaryKey(String name, List<String> pkColumns)
    {
        this.name = name;        
        this.pkColumns = pkColumns;
    }
    public PrimaryKey(String name)
    {
        this.name = name;        
        this.pkColumns = new ArrayList<String>();
    }
    
    public String getName()
    {
        return name;
    }
    public void setName(String name)
    {
        this.name=name;
    }
    
    public List<String> getPKColumns()
    {
        return pkColumns;
    }
    public boolean addPKColumn(String pkColumn)
    {
        for(int i=0;i<pkColumns.size();i++)
        {
            if(pkColumn.equals(pkColumns.get(i)))
            {
                return false;
            }
        } 
        this.pkColumns.add(pkColumn);        
        return true;
    }
    
    public String getPKColumn(int index)
    {
        return pkColumns.get(index);
    }
    public boolean removePKColumn(String pkKeyName)
    {
        for(int i=0;i<pkColumns.size();i++)
        {
            if(pkKeyName.equals(pkColumns.get(i)))
            {
                pkColumns.remove(i);
                return true;
            }
        }
        return false;
    }       
}
